package com.ruoyi.prodata.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.prodata.service.IPaymentStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/prodata/paymentStatistics")
public class PaymentStatisticsController extends BaseController {

    @Autowired
    private IPaymentStatisticsService paymentStatisticsService;

    @GetMapping("/{projectId}")
    public AjaxResult getPaymentStatistics(@PathVariable Long projectId){
        List<Map<String,Object>> list = paymentStatisticsService.getPaymentStatistics(projectId);

        List<String> nameList = new ArrayList<>();
        List<Integer> paidList = new ArrayList<>();
        List<Integer> percentList = new ArrayList<>();

        //容器转换
        list.forEach(m->{
            nameList.add(Convert.toStr(m.get("name")));
            paidList.add(Convert.toInt(m.get("paid")));
            percentList.add(Convert.toInt(m.get("percent")));
        });

        Map<String,Object> map =new HashMap<>();
        map.put("nameList", nameList);
        map.put("paidList",paidList);
        map.put("percentList",percentList);
        map.put("list",list);

        return success(map);
    }
}
